//
//  YZLSearchButtonView.m
//  Car
//
//  Created by dllo on 15/11/5.
//  Copyright © 2015年 岳明. All rights reserved.
//

#pragma mark - **搜索 button

#import "YZLSearchButtonView.h"
#import "Macro.h"

@implementation YZLSearchButtonView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, self.frame.size.height, kWidth, 1)];
        [self addSubview:backView];
        backView.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1];
        
        NSArray *array = @[@"全部", @"文章", @"车系", @"贴吧"];
        
        UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:array];
        segmentedControl.frame = CGRectMake(20, 10, kWidth - 40, self.frame.size.height - 20);
        // 设置默认选择项索引
        segmentedControl.selectedSegmentIndex = 0;
        // 设置按下时的颜色
        segmentedControl.tintColor = [UIColor blueColor];
        // 设置分段控件点击响应事件
        [segmentedControl addTarget:self action:@selector(doSomethingSegment:) forControlEvents:UIControlEventValueChanged];
        
        [self addSubview:segmentedControl];
    }
    return self;
}

- (void)doSomethingSegment:(UISegmentedControl *)seg {
    [self.delegate switchTheViewWithButton:seg];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
